package com.IntelligentCommunity.deploy.run;

import com.IntelligentCommunity.deploy.cache.TaskFaceCache;
import com.IntelligentCommunity.deploy.domain.DeployTaskFace;
import com.IntelligentCommunity.deploy.domain.vo.DeployTaskFaceVO;
import com.IntelligentCommunity.deploy.service.IDeployTaskFaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 美国五星上将麦克阿瑟
 */
@Component
public class CacheJob {

    @Autowired
    private IDeployTaskFaceService deployTaskFaceService;

    // 项目启动运行一遍，之后没十秒运行一次，使用corn表达式
    @Scheduled(cron = "*/10 * * * * ?")
    public void run() {
        List<DeployTaskFaceVO> deployTaskFaces = deployTaskFaceService.selectDeployTaskFaceVOList(null, null, null, null);
        TaskFaceCache instance = TaskFaceCache.getInstance();
        if (instance.size() > 0) {
            instance.getTaskFaceCacheMap().clear();
        }
        for (DeployTaskFaceVO deployTaskFace : deployTaskFaces) {
            instance.put("face,"+deployTaskFace.getId(), deployTaskFace);
        }
    }

}
